<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>注册 - layuiAdmin</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/static/lib/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/lib/layuiadmin/style/admin.css" media="all">
    <link rel="stylesheet" href="/static/lib/layuiadmin/style/login.css" media="all">
</head>
<body>
<div class="layadmin-user-login layadmin-user-display-show" id="LAY-user-login" style="display: none;">
    <div class="layadmin-user-login-main">
        <div class="layadmin-user-login-box layadmin-user-login-header">
            <h2>云南紫米ERP</h2>
            <p>云南紫米ERP 官方出品的后台管理模板系统</p>
        </div>
        <div class="layadmin-user-login-box layadmin-user-login-body layui-form">
            <div class="layui-form-item">
                <label class="layadmin-user-login-icon layui-icon layui-icon-cellphone"
                       for="phone"></label>
                <input type="text" name="phone" id="phone" maxlength="11" placeholder="手机" class="layui-input">
            </div>
            <div class="layui-form-item">
                <input type="checkbox" name="agreement" lay-skin="primary" title="同意用户协议" checked>
            </div>
            <div class="layui-form-item">
                <button class="layui-btn layui-btn-fluid" lay-submit lay-filter="next">下一步</button>
            </div>
            <div class="layui-trans layui-form-item layadmin-user-login-other">
                <a href="login.html" class="layadmin-user-jump-change layadmin-link layui-hide-xs">用已有帐号登入</a>
                <a href="login.html"
                   class="layadmin-user-jump-change layadmin-link layui-hide-sm layui-show-xs-inline-block">登入</a>
            </div>
        </div>
    </div>

    <div class="layui-trans layadmin-user-login-footer">

        <p>© 2018 <a href="http://www.layui.com/" target="_blank">layui.com</a></p>
        <p>
            <span><a href="http://www.layui.com/admin/#get" target="_blank">获取授权</a></span>
            <span><a href="http://www.layui.com/admin/pro/" target="_blank">在线演示</a></span>
            <span><a href="http://www.layui.com/admin/" target="_blank">前往官网</a></span>
        </p>
    </div>

</div>

<script src="/static/lib/layuiadmin/layui/layui.js"></script>
<script>
    document.getElementById('phone').focus();

    var phone
        ,$
        ,iCount;

    layui.config({
        base: '/static/lib/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'user'], function () {
        var setter = layui.setter
            , admin = layui.admin
            , form = layui.form
            , router = layui.router();
        $ = layui.$;
        form.render();

        // 免费获取验证码
        form.on('submit(retryVerify)', function (obj) {
            $.ajax({
                url: '/registry/retrySendVerifiNumber' //实际使用请改成服务端真实接口
                , data: {}
                , method: 'post'
                , success: function (res) {
                    layer.msg('验证码已经发送到手机，请验收。', {
                        offset: '15px'
                        , icon: 1
                        , time: 1000
                    }, function () {
                        var count = 60;
                        $('#phoneLabel').html(phone);
                        $('#retry').html('重发验证码(' + count + ' s)');
                        $('#retry').addClass("layui-btn-disabled");
                        document.getElementById('verifyCode').focus();

                        iCount = setInterval(() => {
                            count--;
                            if (count <= 0) {
                                clearInterval(iCount);

                                $('#retry').html('免费获取验证码');
                                $('#retry').removeClass("layui-btn-disabled");
                            } else {
                                $('#retry').html('重发验证码(' + count + ' s)');
                            }
                        }, 1000, count);
                    });

                }, error: function (res) {
                    return layer.msg(res.msg, {
                        anim: 6
                        , icon: 5
                        , time: 1000
                    });
                }
            });

            return false;
        });

        // 确认
        form.on('submit(formSubmit)', function (obj) {
            var field = obj.field;
            $.ajax({
                url: '/registry/verification' //实际使用请改成服务端真实接口
                , data: field

                , method: 'post'
                , success: function (res) {
                    if (res.code == 0) {
                        window.location.href = "/registry/page2";
                    } else {
                        return layer.msg(res.msg, {
                            anim: 6
                            , icon: 5
                            , time: 1000
                        },function(){
                            window.location.href = "/";
                        });
                    }
                }, error: function (res) {
                    return layer.msg(res.msg, {
                        anim: 6
                        , icon: 5
                        , time: 1000
                    });
                }
            });

            return false;
        });

        //提交
        form.on('submit(next)', function (obj) {
            var field = obj.field;

            //确认密码
            if (field.phone.length != 11) {
                return layer.msg('请输入正确格式的手机号。', {
                    anim: 6
                    , icon: 5
                    , time: 1000
                });
            } else {
                var patt1 = new RegExp("^((13[0-9])|(14[5,7,9])|(15([0-3]|[5-9]))|(166)|(17[0,1,3,5,6,7,8])|(18[0-9])|(19[8|9]))\\d{8}$");
                if (!patt1.test(field.phone)) {
                    return layer.msg('请输入正确格式的手机号。', {
                        anim: 6
                        , icon: 5
                        , time: 1000
                    });
                }
            }

            phone = field.phone;

            //请求接口
            $.ajax({
                url: '/registry/sendVerifiNumber' //实际使用请改成服务端真实接口
                , data: field
                , method: 'post'
                , success: function (res) {
                    if (res.code == 0) {
                        layer.open({
                            title: "验证手机",
                            type: 1
                            ,area: ['530px', '360px'] //宽高
                            , content: $('#dialog-block')
                            , success: function (layero, index) {
                                var count = 60;
                                $('#phoneLabel').html(phone);
                                $('#retry').html('重发验证码(' + count + ' s)');
                                $('#retry').addClass("layui-btn-disabled");
                                document.getElementById('verifyCode').focus();

                                iCount = setInterval(() => {
                                    count--;
                                    if (count <= 0) {
                                        clearInterval(iCount);

                                        $('#retry').html('免费获取验证码');
                                        $('#retry').removeClass("layui-btn-disabled");
                                    } else {
                                        $('#retry').html('重发验证码(' + count + ' s)');
                                    }
                                }, 1000, count);
                            }
                            , end: function () {
                                //关闭窗口执行的操作
                                clearInterval(iCount);
                            }
                        });
                    } else {
                        return layer.msg(res.msg, {
                            anim: 6
                            , icon: 5
                            , time: 1000
                        });
                    }
                }, error: function (res) {
                    return layer.msg(res.msg, {
                        anim: 6
                        , icon: 5
                        , time: 1000
                    });
                }
            });

            return false;
        });
    });

</script>
</body>
</html>

<div id="dialog-block" style="height:200px; display: none; margin-top: 10px; padding-left: 10px;">
    <i class="layui-icon layui-icon-tips" style="font-size: 15px; color: #1E9FFF;">校验码已发送到你的手机，15分钟内输入有效，请勿泄漏</i>
    <form class="layui-form" action="" lay-filter="component-form-group" style="margin-top:30px;">
        <div class="layui-form-item">
            <label class="layui-form-label">手机号： </label>
            <div class="layui-input-block">
                <label id="phoneLabel" class="layui-form-label" style="width:100px;text-align: left"></label>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">校验码：</label>
            <div class="layui-input-block" style="width: 400px">
                <input name="verifyCode" style="width: 150px;float:left;" maxlength="6" id="verifyCode"
                       placeholder="请输入校验码" lay-verify="verifyCode" class="layui-input" autocomplete="off">
                <button id="retry" class="layui-btn" style="width: 200px;float:left;" lay-submit
                        lay-filter="retryVerify"></button>
            </div>
            <div class="layui-input-block" style="width: 400px; margin-top:10px;">
                <button class="layui-btn" lay-submit lay-filter="formSubmit" style="width: 200px;">确认</button>
            </div>
        </div>
    </form>
</div>